package framework.objects.ui.buttons;

import android.view.MotionEvent;
import framework.GameCamera;
import framework.GameScreen;
import framework.managers.SystemInfoManager;
import framework.objects.ui.UI;

public abstract class RectSingletouchButton extends Button {

	public RectSingletouchButton(GameScreen screen, UI ui, float x0, float y0) {
		super(screen, ui, x0, y0);
	}

	@Override
	protected void onOut() {
	}

	@Override
	protected void onOver() {
	}

	@Override
	public void handle(MotionEvent event) {
		float touchX = event.getX();
		float touchY = event.getY();
		if ((Math.abs(touchX / SystemInfoManager.getScaleX() - x0) <= width / 2)
				&& (Math.abs(touchY / SystemInfoManager.getScaleY() - (GameCamera.CAMERA_HEIGHT - y0)) <= height / 2)) {
			int action = event.getAction();
			if (action == MotionEvent.ACTION_DOWN) {
				onDown();
			}
			if (action == MotionEvent.ACTION_UP) {
				onUp();
			}
		}
	}

}
